package com.ntd.study.protocol.emq;

import com.ntd.study.protocol.emq.core.NtdMqttClient;
import com.ntd.study.protocol.emq.factory.NtdMqttClientFactory;
import org.eclipse.paho.client.mqttv3.MqttException;

/**
 * @author liuwenju
 * @date 2021/4/15
 */
public class EmqClientPubDemo {

    public static void main(String[] args) throws MqttException {
        // mqttConfig.setSslPath("C:\\Users\\Administrator\\Desktop\\fsdownload\\client.crt");
        NtdMqttClientFactory.TCP_FM_1883.init();

        NtdMqttClient client = new NtdMqttClient(NtdMqttClientFactory.TCP_FM_1883);

//        JSONObject jsonObject = new JSONObject();
//        jsonObject.putOnce("mn", "123456");
//        jsonObject.putOnce("ts", DateUtil.currentSeconds());
//        jsonObject.putOnce("cmd_id", "56395");
//        jsonObject.putOnce("action", "update");
//
//        JSONObject params = new JSONObject();
//
//        params.putOnce("code001", "123456");
//
//        JSONObject preOps = new JSONObject();
//        preOps.putOnce("code002", "456132");
//        params.put("pre_ops", preOps);
//        JSONObject postOps = new JSONObject();
//        postOps.putOnce("code003", "456dsfd132");
//        params.putOnce("post_ops", postOps);
//
//        jsonObject.putOnce("params", params);
//
//        client.sendMessage("demo_cmd", jsonObject.toString());

        sendTest1(client);

        client.close();
        System.exit(0);
    }

    private static void sendTest1(NtdMqttClient client) throws MqttException {
        client.sendMessage("demo_data123456", "Hello World");
    }
}
